this.xgread = (function () {

  var xgread = {};

  var logUtils$3 = {
      showing: false,
      show () {
        console.show ();
        this.showing = true;
      },
      hide () {
        console.hide ();
        this.showing = false;
      },
      log () {
        console.log.apply (console, arguments);
      },
    };

  var gUtils$2 = {
    random(min, max) {
      return random(min, max);
    },
    sleep(start, end) {
      var duration = this.random(start, end);
      this.sleep$(duration);
      return duration;
    },
    sleep$(duration) {
      sleep(duration * 1000);
    },
    possible(start, end, scale) {
      var scale = scale || 100;
      var v = this.random(1, scale);
      return v >= start && v <= end;
    },
    hasExec(startTime) {
      var now = Date.now();
      return parseInt((now - startTime) / 1000);
    },
    getMin(v) {
      return v / 60;
    },
  };

  var deviceUtils$2 = {
    lockScreen() {
      var cmd = "input keyevent 26";
      shizuku(cmd);
    },
    back() {
      var cmd = "input keyevent 4";
      shizuku(cmd);
    },
    home() {
      var cmd = "input keyevent 3";
      shizuku(cmd);
    },
    recents() {
      var cmd = "input keyevent 187";
      shizuku(cmd);
    },
  };

  var clickUtils$3 = {
    getRateX(x, w) {
      return parseInt(x * (device.width / (w || device.width)));
    },
    getRateY(y, h) {
      return parseInt(y * (device.height / (h || device.height)));
    },
    clickXY(x, y) {
      var cmd = "input tap " + x + " " + y;
      console.error("x:", x, "y:", y);
      shizuku(cmd);
    },
    clickXYZW(x, y, z, w, deltaX, deltaY) {
      var maxDeltaX = Math.abs(z - x) / 2;
      var maxDeltaY = Math.abs(w - y) / 2;
      deltaX = deltaX || 1;
      deltaY = deltaY || 1;
      deltaX = deltaX > maxDeltaX ? maxDeltaX - 2 : deltaX;
      deltaY = deltaY > maxDeltaY ? maxDeltaY - 2 : deltaY;
      this.clickXY(
        random(x + deltaX, z - deltaX),
        random(y + deltaY, w - deltaY)
      );
    },
    clickBounds(bounds, deltaX, deltaY) {
      var left = bounds.left;
      var right = bounds.right;
      var top = bounds.top;
      var bottom = bounds.bottom;
      console.log(left, top, right, bottom);
      this.clickXYZW(left, top, right, bottom, deltaX, deltaY);
    },
    clickPointMap(pointMap, deltaX, deltaY) {
      var point = pointMap[0];
      var width = pointMap[1];
      var height = pointMap[2];
      var x = this.getRateX(point[0], width);
      var y = this.getRateY(point[1], height);
      var z = this.getRateX(point[2], width);
      var w = this.getRateY(point[3], height);
      this.clickXYZW(x, y, z, w, deltaX, deltaY);
    },
    clickTextUI(TextUI, deltaX, deltaY) {
      this.clickBounds(TextUI.bounds(), deltaX, deltaY);
    },
    clickTextOCR(TextOCR, deltaX, deltaY) {
      console.log(TextOCR.bounds);
      this.clickBounds(TextOCR.bounds, deltaX, deltaY);
    },
  };

  var swipeUtils$2 = {
    swipe(a, b, c, d, duration) {
      var cmd = "input swipe " + a + " " + b + " " + c + " " + d + " " + duration;
      shizuku(cmd);
    },
  };

  var activityMap$1 = {
    抖音火山版:
      "com.ss.android.ugc.live/com.ss.android.ugc.aweme.splash.SplashActivity",
  };

  var logUtils$2 = logUtils$3;
  var gUtils$1 = gUtils$2;
  var deviceUtils$1 = deviceUtils$2;
  var clickUtils$2 = clickUtils$3;
  var swipeUtils$1 = swipeUtils$2;
  var activityMap = activityMap$1;
  var pointMap$1 = {
    关闭所有应用: [[420, 2006, 660, 2246], 1080, 2340],
  };
  var appUtils$1 = {
    appName: null,
    openApp(appName) {
      var activity = activityMap[appName];
      if (activity) {
        shizuku("am start " + activity);
        return;
      }
      this.appName = appName;
      var result = app.launchApp(appName);
      logUtils$2.log(appName.length);
      logUtils$2.log("打开：", appName, result ? "成功" : "失败");
      sleep(2 * 1000);
      return result;
    },
    closeRecent() {
      deviceUtils$1.home();
      sleep(2 * 1000);
      deviceUtils$1.recents();
      sleep(2 * 1000);
      if (["cannon", "evergo"].includes(device.product)) {
        swipeUtils$1.swipe(
          device.width / 4 + device.width / 8 + device.width / 16,
          device.height / 2,
          device.width / 20,
          device.height / 2,
          200
        );
      } else {
        swipeUtils$1.swipe(
          device.width / 2,
          device.height / 2,
          device.width / 2,
          device.height / 16,
          gUtils$1.random(300, 500)
        );
      }
      sleep(2 * 1000);
      deviceUtils$1.home();
      sleep(2 * 1000);
    },
    closeAll() {
      deviceUtils$1.home();
      sleep(2 * 1000);
      deviceUtils$1.recents();
      sleep(2 * 1000);
      clickUtils$2.clickPointMap(pointMap$1.关闭所有应用);
      sleep(2 * 1000);
    },
    checkInstall(appName) {
      return !!app.getPackageName(appName);
    },
  };

  var ocrCharMap$1 = {
    搜: ["嫂", "樓", "接", "楼"],
    赚: ["廉", "嫌", "賺", "兼"],
    看: ["着", "春"],
    文: ["女"],
    章: ["拿"],
    钱: ["线"],
    觉: ["党"],
    户: ["戶"],
    索: ["素"],
    开: ["升", "研"],
    金: ["全"],
    积: ["枳"],
    币: ["市"],
    现: ["現"],
    领: ["領", "颌", "颁"],
    读: ["渎"],
    额: ["額"],
    取: ["驭"],
    视: ["规", "初"],
    享: ["亨"],
    兑: ["兌"],
    提: ["堤"],
    体: ["休"],
    才: ["オ"],
    街: ["衔"],
    城: ["械"],
    间: ["闻"],
    来: ["來"],
    幕: ["慕"],
    十: ["+"],
    已: ["己"],
    己: ["已"],
    摄: ["攝"],
  };
  var ocrCharMap_1 = ocrCharMap$1;

  var logUtils$1 = logUtils$3;
  var ocrCharMap = ocrCharMap_1;

  // var cpuThreadNum = 4;
  // // PaddleOCR 移动端提供了两种模型：ocr_v3_for_cpu与ocr_v3_for_cpu(slim)，此选项用于选择加载的模型,默认true使用v3的slim版(速度更快)，false使用v3的普通版(准确率更高）
  // var useSlim = true;
  // // 是否使用v4版本
  // var useV4 = false;

  // $ocr.initWithModel({ useV4 });
  var ocrUtils$1 = {
    hasInit: false,
    captureImg: null,
    init() {
      if (this.hasInit) {
        return;
      } else {
        shizuku("appops set org.autojs.autojs6 PROJECT_MEDIA allow");
        this.hasInit = true;
        setTimeout(() => {
          if (!requestScreenCapture()) {
            toastLog("请求截图权限失败");
            exit();
          }
        }, 1000);
      }
    },
    updateCaptureImg() {
      var startTime = Date.now();
      var showing = logUtils$1.showing;
      if (showing) {
        logUtils$1.hide();
        sleep(0.1 * 1000);
      }
      this.captureImg = captureScreen();
      setTimeout(() => {
        this.captureImg && this.captureImg.recycle();
      }, 1000);
      if (showing) {
        logUtils$1.show();
      }
      if (!this.captureImg) {
        toastLog("截图失败");
      }
      var endTime = Date.now();
      var hasExec = (endTime - startTime) / 1000;
      if (hasExec > 1) {
        logUtils$1.log("GCI: 截图耗费-" + hasExec + "-s");
      }
    },
    getOcrResults() {
      console.log("开始识别");
      // var ocrResults = ocr.paddle.detect(this.captureImg, {
      var ocrResults = ocr.mlkit.detect(this.captureImg, {
        useSlim: false,
        cpuThreadNum: 4,
      });
      if (Array.isArray(ocrResults)) {
        return ocrResults.map((item) => {
          var obj = {};
          obj.text = item.label;
          obj.bounds = item.bounds;
          obj.confidence = item.confidence;
          return obj;
        });
      }
      return ocrResults;
    },

    getRegExpConfig(content) {
      var regExpStr = content
        .split("")
        .map(function (item) {
          var match = ocrCharMap[item];
          var piece = match
            ? "[" + match.concat(item).join("") + "]+"
            : "[" + item + "]+";
          return piece + `\\s*`;
        })
        .join("");
      return {
        text: content,
        regExp: new RegExp(regExpStr, "gi"),
      };
    },
    captureAndLog() {
      var ocrResults = this.getOcrResults();
      this.logOcrResults(ocrResults);
    },
    logOcrResults(ocrResults) {
      logUtils$1.log(typeof ocrResults);
      if (Array.isArray(ocrResults)) {
        console.show();
        logUtils$1.log(
          "LOR1:",
          "\n",
          ocrResults.map((item) => item.text).join(",")
        );
      } else {
        console.show();
        logUtils$1.log("LOR2:", "\n", JSON.stringify(ocrResults)); // TODO: 待确认是否需要do
      }
    },
    ocrResultsExist(ocrResults, regExpConfig) {
      for (var index = 0; index < ocrResults.length; index++) {
        var ocrResult = ocrResults[index];
        if (regExpConfig.regExp.test(ocrResult.text)) {
          return ocrResult;
        }
      }
      return false;
    },
    regExpConfigExist(ocrResults, regExpConfigs) {
      for (var index = 0; index < ocrResults.length; index++) {
        var ocrResult = ocrResults[index];
        for (var index2 = 0; index2 < regExpConfigs.length; index2++) {
          var regExpConfig = regExpConfigs[index2];
          if (regExpConfig.regExp.test(ocrResult.text)) {
            return ocrResult;
          }
        }
      }
      return false;
    },
    regExpConfigExistSome(ocrResults, regExpConfigs) {
      var results = [];
      for (var index = 0; index < ocrResults.length; index++) {
        var ocrResult = ocrResults[index];
        for (var index2 = 0; index2 < regExpConfigs.length; index2++) {
          var regExpConfig = regExpConfigs[index2];
          if (regExpConfig.regExp.test(ocrResult.text)) {
            results.push(ocrResult);
          }
        }
      }
      return results;
    },
    captureExistsText(content, logOcrResults, ignoreLog) {
      var regExpConfig = this.getRegExpConfig(content);
      var ocrResults = this.getOcrResults();
      var ocrResult = this.ocrResultsExist(ocrResults, regExpConfig);
      if (ocrResult) {
        if (!ignoreLog) {
          logUtils$1.log("CET:", "找到", regExpConfig.text, "/", ocrResult.text);
        }
        return ocrResult;
      } else {
        if (logOcrResults) {
          this.logOcrResults(ocrResults);
        }
        return false;
      }
    },
    captureExistsOneText(contents, logOcrResults, ignoreLog) {
      if (!Array.isArray(contents)) {
        contents = [contents];
      }
      var ocrResults = this.getOcrResults();
      var regExpConfigs = contents.map((content) =>
        this.getRegExpConfig(content)
      );
      var ocrResult = this.regExpConfigExist(ocrResults, regExpConfigs);
      if (ocrResult) {
        if (!ignoreLog) {
          logUtils$1.log("CEOT:", "找到", contents.join(","), "/", ocrResult.text);
        }
        return ocrResult;
      } else {
        logUtils$1.log("CEOT:", "没找到", contents.join(","));
        if (logOcrResults) {
          this.logOcrResults(ocrResults);
        }
        return false;
      }
    },
    captureExistsSomeText(contents, logOcrResults, ignoreLog) {
      if (!Array.isArray(contents)) {
        contents = [contents];
      }
      var ocrResults = this.getOcrResults();
      var regExpConfigs = contents.map((content) =>
        this.getRegExpConfig(content)
      );
      var results = this.regExpConfigExistSome(ocrResults, regExpConfigs);
      if (results.length > 0) {
        if (!ignoreLog) {
          logUtils$1.log(
            "CEOT:",
            "找到",
            contents.join(","),
            "/",
            results.map((item) => item.text).join(",")
          );
        }
        return results;
      } else {
        logUtils$1.log("CEOT:", "没找到", contents.join(","));
        if (logOcrResults) {
          this.logOcrResults(ocrResults);
        }
        return false;
      }
    },

    captureExistsAllText(contents, logOcrResults, ignoreLog) {
      if (!Array.isArray(contents)) {
        contents = [contents];
      }
      var ocrResults = this.getOcrResults();
      var regExpConfigs = contents.map((content) =>
        this.getRegExpConfig(content)
      );
      var findResults = [];
      for (var index = 0; index < regExpConfigs.length; index++) {
        var regExpConfig = regExpConfigs[index];
        var ocrResult = this.ocrResultsExist(ocrResults, regExpConfig);
        if (ocrResult) {
          findResults.push(ocrResult);
        }
      }
      if (findResults.length == contents.length) {
        if (!ignoreLog) {
          logUtils$1.log(
            "CEAT:",
            "找到",
            "\n",
            contents.join(","),
            "\n",
            findResults.map((item) => item.text).join(",")
          );
        }
        return true;
      } else {
        logUtils$1.log("CEAT:", "没找到", contents.join(","));
        if (logOcrResults) {
          this.logOcrResults(ocrResults);
        }
        return false;
      }
    },
  };

  var logUtils = logUtils$3;
  var gUtils = gUtils$2;
  var deviceUtils = deviceUtils$2;
  var appUtils = appUtils$1;
  var clickUtils$1 = clickUtils$3;
  var swipeUtils = swipeUtils$2;
  var ocrUtils = ocrUtils$1;

  var shizukuUtils = {
    logUtils: logUtils,
    gUtils: gUtils,
    deviceUtils: deviceUtils,
    appUtils: appUtils,
    clickUtils: clickUtils$1,
    swipeUtils: swipeUtils,
    ocrUtils: ocrUtils,
  };

  var packageNameMap$1 = {
    快手极速版: "com.kuaishou.nebula",
    快手极速: "com.kuaishou.nebula",
    喜番免费短剧: "com.kwai.theater",
    抖音极速版: "com.ss.android.ugc.aweme.lite",
    抖音极速: "com.ss.android.ugc.aweme.lite",
    抖音火山版: "com.ss.android.ugc.live",
    火山: "com.ss.android.ugc.live",
    抖音商城: "com.ss.android.ugc.livelite",
    商城: "com.ss.android.ugc.livelite",
    抖音: "com.ss.android.ugc.aweme",

    今日头条: "com.ss.android.article.news",
    头条: "com.ss.android.article.news",
    有柿: "com.ss.android.article.search",
    有: "com.ss.android.article.search",
    头条搜索极速版: "com.ss.android.article.lite",
    头条搜索: "com.ss.android.article.lite",
    红果免费短剧: "com.phoenix.read",
    红果: "com.phoenix.read",
    悟空浏览器: "com.cat.readall",
    悟空: "com.cat.readall",

    西瓜视频: "com.ss.android.article.video",
    西瓜: "com.ss.android.article.video",
    百度畅听版: "com.baidu.searchbox.tomas",
    百度畅听: "com.baidu.searchbox.tomas",
    百度极速版: "com.baidu.searchbox.lite",
    百度极速: "com.baidu.searchbox.lite",
    袋鼠点点短视频: "com.zhangyue.app.shortvideo",
    袋鼠: "com.zhangyue.app.shortvideo",
    快手: "com.smile.gifmaker",
    快: "com.smile.gifmaker",

    番茄免费小说: "com.dragon.read",
    番茄: "com.dragon.read",
    番茄畅听: "com.xs.fm",
    番茄畅听音乐版: "com.xs.fm.lite",
    番茄音乐: "com.xs.fm.lite",
    蛋花免费小说: "com.eggflower.read",
    蛋花: "com.eggflower.read",
    常读免费小说: "com.woodleaves.read",
    常读: "com.woodleaves.read",
  };

  var appNameMap$1 = {
    快手极速版: "快手极速版",
    快手极速: "快手极速",

    抖音极速版: "抖音极速版",
    抖音极速: "抖音极速",

    抖音火山版: "抖音火山版",
    火山: "火山",

    抖音商城: "抖音商城",
    商城: "商城",

    抖音: "抖音",

    今日头条: "今日头条",
    头条: "头条",

    有柿: "有柿",
    有: "有",

    头条搜索极速版: "头条搜索极速版",
    头条搜索: "头条搜索",

    红果免费短剧: "红果免费短剧",
    红果: "红果",

    悟空浏览器: "悟空浏览器",
    悟空: "悟空",

    西瓜视频: "西瓜视频",
    西瓜: "西瓜",

    百度畅听版: "百度畅听版",
    百度畅听: "百度畅听",

    百度极速版: "百度极速版",
    百度极速: "百度极速",

    袋鼠点点短视频: "袋鼠点点短视频",
    袋鼠: "袋鼠",

    快手: "快手",
    快: "快",

    番茄免费小说: "番茄免费小说",
    番茄: "番茄",

    番茄畅听: "番茄畅听",

    番茄畅听音乐版: "番茄畅听音乐版",
    番茄音乐: "番茄畅听音乐版",

    蛋花免费小说: "蛋花免费小说",
    蛋花: "蛋花",

    常读免费小说: "常读免费小说",
    常读: "常读",

    喜番免费短剧: "喜番免费短剧",
    快手短剧: "喜番免费短剧",
    喜番: "喜番免费短剧",

    快手免费小说: "快手免费小说",
    快手小说: "快手免费小说",

    auto: "AutoJs6",
    autojs: "AutoJs6",
    0: "AutoJs6",
  };

  var time = {
    random(start, end) {
      return random(start, end);
    },
    randomS(min, max) {
      return random(min * 1000, max * 1000);
    },
    randomM(min, max) {
      return random(min * 60 * 1000, max * 60 * 1000);
    },
    getS(v) {
      return Math.floor(v / 1000);
    },
    getM(v) {
      return Math.floor(v / 60 / 1000);
    },
    hasExec(start) {
      var now = Date.now();
      return Math.floor((now - start) / 1000);
    },
    sleep(start, end) {
      var secs = this.random(start, end);
      sleep(secs * 1000);
      return secs;
    },
    sleepM(start, end) {
      var mn = this.random(start, end);
      sleep(mn * 60 * 1000);
      return mn;
    },
    getMin(sec) {
      return Math.floor(sec / 60);
    },
    possible(start, end, scale) {
      scale = scale || 100;
      var v = this.random(1, scale);
      return v >= start && v <= end;
    },
  };

  var packageNameMap = packageNameMap$1;
  var appNameMap = appNameMap$1;
  var timeHelper$1 = time;
  var app_1 = {
    getPackageName(appName) {
      return packageNameMap[appName];
    },
    goAutojs() {
      return this.launchApp("auto");
    },
    launchPackage(appName) {
      var packageName = this.getPackageName(appName);
      var result = app.launchPackage(packageName);
      if (!result) {
        console.log(`launchPackage ${appName} 失败了!!!`);
      }
      return result;
    },
    launchApp(appName) {
      var appName$ = appNameMap[appName] || appName;
      var result = app.launchApp(appName$);
      if (!result) {
        console.log(`launchApp ${appName} 失败了!!!`);
        return this.launchPackage(appName);
      }
      return result;
    },
    goAutojsThenOpen(appName, start, end) {
      if (!this.goAutojs()) {
        return false;
      }
      timeHelper$1.sleep(2, 4);
      return this.launchApp(appName);
    },
  };

  var device_1 = {
    goHome() {
      var intent = new Intent();
      intent.setAction(Intent.ACTION_MAIN);
      intent.addCategory(Intent.CATEGORY_HOME);
      app.startActivity(intent);
    },
    goSetting() {
      var intent = new Intent();
      intent.setAction("android.settings.SETTINGS");
      app.startActivity(intent);
    },
    wakeUp() {
      return device.wakeUp();
    },
    getBattery() {
      return device.getBattery();
    },
    getAndroidId() {
      return device.getAndroidId();
    },
  };

  var deviceHelper = device_1;
  function getPhoneNumber(v) {
    const phoneNumberMap = {
      "08f39272005fbbf9": "18762750392",
      "1d2a32368fe6239d": "13065826251",
      "271b4a9052a3501c": "17704040918",
      "15e2ab0630873018": "13056768975",
      "d17a392b04a92a80": "15626591667",
      "e864bcdddfb104cf": "15212331291",
      "fd826f6ec3acf40c": "15212331276",
      "4959d47c74e79f00": "15212331201",
      "886b260a566ebda2": "17764297074",
      "8f8acfc5b649c33f": "15523623349",
      "fccc893185006249": "13193037083",
      "f276d54a1a6861d2": "19858302953",
      "1c73bd770f1da671": "18042059337",
      "6f042bfd09ad08e1": "14751017521",
    };
    return phoneNumberMap[v] || v;
  }
  var log = {
    post(data) {
      var url = "http://47.120.74.135" + "/api/log/add";
      return http.postJson(url, data);
    },
    log(msg, type, curApp) {
      console.log.apply(console, [msg]);
      type = type || 1;
      curApp = curApp || "";
      return this.post({
        curApp,
        battery: deviceHelper.getBattery(),
        type: String(type),
        msg: msg,
        phoneNumber: getPhoneNumber(deviceHelper.getAndroidId()),
        createTime: new Date().toISOString(),
      });
    },
  };

  var helper = {
    appHelper: app_1,
    deviceHelper: device_1,
    packageNameMap: packageNameMap$1,
    appNameMap: appNameMap$1,
    timeHelper: time,
    logHelper: log,
  };

  var { clickUtils } = shizukuUtils;
  var { timeHelper } = helper;
  var pointMap = {
    首页: {
      // 推荐: [[137, 220, 306, 336], 1080, 2340],
      // 关注: [[0, 220, 137, 336], 1080, 2340],
      // 精选: [[306, 220, 443, 336], 1080, 2340],
      首页: [[47, 2176, 168, 2253], 1080, 2340],
      放映厅: [[216, 2165, 432, 2296], 1080, 2340],
      商城: [[648, 2165, 864, 2296], 1080, 2340],
      我的: [[911, 2176, 1032, 2253], 1080, 2340],
    },
  };
  function refresh() {
    if (timeHelper.possible(1, 20)) {
      clickUtils.clickPointMap(pointMap.首页.放映厅);
      timeHelper.sleep(10, 20);
    } else {
      clickUtils.clickPointMap(pointMap.首页.我的);
      timeHelper.sleep(3, 6);
    }
    clickUtils.clickPointMap(pointMap.首页.首页);
  }
  function watch() {
    return timeHelper.sleep(0.5 * 60, 3 * 60);
  }

  Wang.main = function (max) {
    var max = Number(max || 210);
    var hasRead = 0;
    var hasReadMin = 0;
    while (hasReadMin < max) {
      refresh();
      var hasWatch = watch();
      hasRead += hasWatch;
      hasReadMin = timeHelper.getMin(hasRead);
      console.log(`已经看了${hasRead}s,${hasReadMin}min`);
    }
  };

  return xgread;

})();
